$(function () {
    $('.input_sub').on('click', function () {
        let username = $('.input_txt').val()
        let password = $('.input_pass').val()
        $.ajax({
            url: bignews.user_login,
            type: 'post',
            beforeSend: function () {
                if (username.length == 0) {
                    alert('请输入用户名')
                    return false
                } else if (password.length == 0) {
                    alert('请输入密码')
                    return false
                }
            },
            data: { username, password },
            success: function (res) {
                console.log(res)
                if (res.code === 200) {
                    $('#myModal').modal('show')
                    $('.msg').text(res.msg)
                    $('.btn-default').hide()
                    $('#myModal').on('hidden.bs.modal', function (e) {
                        location.href = './index.html'
                    })
                    //将token值存储到本地存储
                    localStorage.setItem('token', res.token)

                } else {
                    $('#myModal').modal('show')
                    $('.msg').text(res.msg)
                }
            },
            dataType: 'json'
        })
    })
    $('.btn-primary').on('click', function () {
        $('#myModal').modal('hide')
    })
})